#define _CRT_SECURE_NO_WARNINGS 1

//P3405 [USACO16DEC] Cities and States S:https://www.luogu.com.cn/problem/P3405

#include <iostream>
#include <unordered_map>

using namespace std;

int main()
{
	unordered_map<string,long long> m;
	int N;
	cin >> N;
	long long ret = 0;
	while (N--)
	{
		string s, c;
		cin >> s >> c;
		s.resize(2);
		if (s != c)
		{
			ret += m[c + s];
			m[s+c]++;
		}

	}

	cout << ret << endl;
	return 0;
}